﻿Imports System.Collections.ObjectModel


''' <summary>
''' 
''' </summary>
''' <remarks></remarks>
Partial Public Class VMParametrage
    Inherits VMBase
    Implements OMANE.Common.UI.IViewModelTabSection

    Dim _Title As String
    Dim _Elements As New ObservableCollection(Of VMParametrageElement)
    Dim _Icone As String
    Dim _Model As IParametrable


    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Sub New()

    End Sub

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="model"></param>
    ''' <remarks></remarks>
    Sub New(ByVal model As IParametrable)
        Me._Model = model
        Reset()
    End Sub

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public ReadOnly Property Parametres As ObservableCollection(Of VMParametrageElement)
        Get
            Return _Elements
        End Get
    End Property

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property Icone As String Implements Common.UI.IViewModelTabSection.Icone
        Get
            Return _Icone
        End Get
        Set(ByVal value As String)
            _Icone = value
        End Set
    End Property

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property Title As String Implements Common.UI.IViewModelTabSection.Title
        Get
            Return _Title
        End Get
        Set(ByVal value As String)
            _Title = value
        End Set
    End Property

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub Reset()
        Dim elts = _Model.GetParametres()
        AddHandler elts.CollectionChanged, AddressOf ModelParametresChanged
        ModelParametresChanged(Nothing, Nothing)
    End Sub

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="name"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function BuildElement(ByVal name As String) As VMParametrageElement
        Return New VMParametrageElement(Me, name)
    End Function

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub ModelParametresChanged(ByVal sender As Object, ByVal e As Specialized.NotifyCollectionChangedEventArgs)
        _Elements = New ObservableCollection(Of VMParametrageElement)( _
                        (From elt In _Model.GetParametres() Select BuildElement(elt)).AsEnumerable())
    End Sub

End Class

